set scheme white_hue
use Dataset.dta, clear


/* Figure 1 */
preserve
collapse (mean) meanDV=DV_vote_n (sd) sdDV=DV_vote_n (count) n=DV_vote_n, by(treatment)
gen DV_hi = meanDV + invttail(n-1,0.025)*(sdDV/sqrt(n))
gen DV_low = meanDV - invttail(n-1,0.025)*(sdDV/sqrt(n))

graph twoway (bar meanDV treatment, barwidth(0.5)) (rcap DV_hi DV_low treatment, lcolor(black)), ///
	yscale(ra(0 1)) ylabel(0(0.2)1)  ///
	xlabel(0 `" "Low" "(inexperienced)" "' 1 `" "Low" "(experienced)" "' ///
	2 `" "High" "(inexperienced)" "' 3 `" "High" "(experienced)" "') ///
	xtitle("") ///
	ytitle("Proportion of voting") legend(off) 
restore

/* Table 2 */
reg DV_vote_n voice experience
est sto	m1

reg DV_vote_n voice##experience
est sto	m2

reg DV_vote_n voice experience male college age income
est sto	m3

reg DV_vote_n voice##experience male college age income
est sto	m4

esttab m1 m2 m3 m4  
 
 
/* Table 3 */
reg DV_vote_n male##voice experience college age income
est sto	m5

reg DV_vote_n college##voice experience male age income
est sto	m6

reg DV_vote_n c.age##voice experience male college income
est sto	m7

reg DV_vote_n c.income##voice experience male college age
est sto	m8

esttab m5 m6 m7 m8


/* Figure 2 */
reg DV_vote_n male##voice experience college age income
margins, at(voice=(0 1) male=(0 1))  level(95)
	mplotoffset, offset(0.2) recast(scatter) recastci(rspike) /// 
		plot1opts(msize(large) msymbol(O))  ///
		plot2opts(msize(large) msymbol(S)) ///
		xlabel(0 "Low voice" 1 "High voice", labsize(medsmall) nogrid) /// 
		xscale(ra(0 1)) yscale(ra(0 1)) ylabel(0(0.2)1) ///
		ylabel(,nogrid) ///
		xtitle("") ///
		ytitle("") ///
		legend(order(1 "Female" 2 "Male")) ///
		graphregion(margin(small) color(white)) plotregion(lcolor(black)) ///
		title("Effect of voice by respondents' gender", size(medium) color(black) ///
		box bexpand nospan bcolor(gs14) lcolor(black)) 


/* Table A.1 and A.2 */
tabstat male college age income, stat(n min max mean sd var)

bysort treatment: sum DV_vote_n male college age income
mvtest means DV_vote_n, by(treatment) 
mvtest means male, by(treatment) 
mvtest means college, by(treatment)
mvtest means age, by(treatment) 
mvtest means income, by(treatment) 

  
/* Table A.3 */
reg DV_vote_n male##voice##experience college age income
est sto	m9

reg DV_vote_n college##voice##experience male age income
est sto	m10
		
reg DV_vote_n c.age##voice##experience male college income
est sto	m11

reg DV_vote_n c.income##voice##experience male college age 
est sto	m12

esttab m9 m10 m11 m12 


/* Figure A.1 */ 
preserve
collapse (mean) meanDV=DV_vote_n (sd) sdDV=DV_vote_n (count) n=DV_vote_n, by(male voice)

gen DV_hi = meanDV + invttail(n-1,0.025)*(sdDV/sqrt(n))
gen DV_low = meanDV - invttail(n-1,0.025)*(sdDV/sqrt(n))

drop if _n == 3 
drop if _n == 5
gen order = _n
recode order (2 = 3) (3 = 2), gen(order_n)

graph twoway (bar meanDV order_n, barwidth(0.5)) (rcap DV_hi DV_low order_n, lcolor(black)), ///
	yscale(ra(0 1)) ylabel(0(0.2)1)  ///
	xlabel(1 `" "Low voice" "(female)" "' 2 `" "Low voice" "(male)" "' 3 `" "High voice" "(female)" "' 4 `" "High voice" "(male)" "') ///
	xtitle("") ///
	ytitle("Proportion of voting") legend(off) 
restore


/* Figure A.2 */
reg DV_vote_n college##voice experience male age income
margins, at(voice=(0 1) college=(0 1))  level(95)
	mplotoffset, offset(0.2) recast(scatter) recastci(rspike) /// 
		plot1opts(msize(large) msymbol(O)) ///
		plot2opts(msize(large) msymbol(S)) ///
		xlabel(0 "Low voice" 1 "High voice", labsize(medsmall) nogrid) /// 
		xscale(ra(0 1)) yscale(ra(0 0.6)) ylabel(0(0.2)0.6) ///
		ylabel(,nogrid) ///
		xtitle("") ///
		ytitle("") ///
		legend(order(1 "No college" 2 "College")) ///
		graphregion(margin(small) color(white)) plotregion(lcolor(black)) ///
		title("Effect of voice by respondents' education", size(medium) color(black) ///
		box bexpand nospan bcolor(gs14) lcolor(black)) 

 
